<template>
  <div class="myAddress">
    <div class="van-nav-bar">
      <div class="van-nav-bar-left"
           @click="back ">
        <van-icon size="16"
                  name="arrow-left"
                  color="#FFF" />返回
      </div>
      <div class="van-nav-bar-title">我的地址</div>
    </div>
    <div>
      <van-address-list :list="list"
                        default-tag-text="默认"
                        :switchable="false"
                        @add="addAddress"
                        @edit="onEdit" />
    </div>
    <div v-if="list.length == 0">
      <van-empty description="没有地址" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'MyAddress',
  data () {
    return {
      list: [],
    };
  },

  created () {
    this.getMyAddressData();
  },

  methods: {
    back () {
      //返回上一级
      this.$router.go(-1);

    },

    //获取用户的地址
    getMyAddressData () {
      this.axios({
        method: 'get',
        url: '/findAddress'
      }).then(result => {

        if (result.data.code == 20000) {
          result.data.result.forEach(ele => {

            ele.address = `${ele.province} ${ele.city} ${ele.county} ${ele.addressDetail}`;


          });

          this.list = result.data.result
        }
      })
    },

    //新增地址
    addAddress () {
      this.$router.push({ name: 'Address' });
    },

    //编辑地址
    onEdit (ele) {

      this.$router.push({ name: 'Address', query: { aid: ele.aid } });
    }
  }
}
</script>

<style lang="scss" scoped>
.myAddress {
  padding-top: 60px;
  .van-nav-bar {
    position: fixed;
    z-index: 999999;
    top: 0;
    left: 0;
    right: 0;
    padding-top: 30px;
    padding-bottom: 10px;
    display: flex;
    align-items: center;
    background-color: #0c34ba;
    color: #fff;

    .van-nav-bar-title {
      margin-left: 115px;
      font-size: 16px;
    }
    .van-nav-bar-left {
      font-size: 16px;
    }
  }
  .van-address-item .van-radio__icon--checked .van-icon {
    background-color: #0c34ba;
    border-color: #0c34ba;
  }

  .van-tag--danger {
    background-color: #0c34ba;
  }

  .van-button--danger {
    background-color: #0c34ba;
    border-color: #0c34ba;
  }
}
</style>